﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NET.Library.Types;

namespace NET.Library.Web.Forms.DataControls.FormViews
{
    /// <summary>
    /// 
    /// </summary>
    public class FormViewValues : NET.Library.Types.Strings
    {
        #region TextBox Controls
        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert TextBox text in a FormView to an Integer value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="textBoxName"></param>
        /// <returns>Integer</returns>
        /// '-----------------------------------------------------------------------------------------
        public static int IntTextBoxValue(FormView formView, string textBoxName)
        {
            TextBox textBox = FormViewControls.TextBoxControl(textBoxName, formView);
            return Values.IntTextValue(textBox);
        }
       
        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert TextBox text in a FormView to a Decimal value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="textBoxName"></param>
        /// <returns>decimal</returns>
        /// '-----------------------------------------------------------------------------------------
        public static decimal DecimalTextBoxValue(FormView formView, string textBoxName)
        {
            TextBox textBox = FormViewControls.TextBoxControl(textBoxName, formView);
            return Values.DecimalTextValue(textBox);
        }

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Get TextBox text in a FormView to a string value by using the FCS method Values.StringTextValue
        /// to remove invalid characters and trim the string.
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="textBoxName"></param>
        /// <returns>string</returns>
        /// <remarks></remarks>
        /// <example></example>
        /// '-----------------------------------------------------------------------------------------
        public static string StringTextBoxValue(FormView formView, string textBoxName)
        {
            TextBox textBox = FormViewControls.TextBoxControl(textBoxName, formView);
            return Values.StringTextValue(textBox);
        }

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert TextBox text in a FormView to a DateTime value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="textBoxName"></param>
        /// <returns>DateTime</returns>
        /// <remarks></remarks>
        /// <example></example>
        /// '-----------------------------------------------------------------------------------------
        public static DateTime DateTimeTextBoxValue(FormView formView, string textBoxName)
        {
            TextBox textBox = FormViewControls.TextBoxControl(textBoxName, formView);
            
            if (IsEmptyString(Values.StringTextValue(textBox)))
            {
                return DateTimes.MinDateTime;
            }
            else
            {
                return Values.DateTimeTextValue(textBox);
            }
        }
    #endregion

        #region Label Controls
        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert Label text in a FormView to an Integer value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="labelName"></param>
        /// <returns>Integer</returns>
        /// <remarks></remarks>
        /// <example></example>
        /// '-----------------------------------------------------------------------------------------
        public static int IntLabelValue(FormView formView, string labelName)
        {
            Label label = FormViewControls.LabelControl(labelName, formView);
            return Values.IntTextValue(label);
        }

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert Label text in a FormView to a Decimal value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="labelName"></param>
        /// <returns></returns>
        /// '-----------------------------------------------------------------------------------------
        public static decimal DecimalLabelValue(FormView formView, string labelName)
        {
            Label label = FormViewControls.LabelControl(labelName, formView);
            return Values.DecimalTextValue(label);
        }

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Get Label text in a FormView to a string value by using the FCS method Values.StringTextValue
        /// to remove invalid characters and trim the string.
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="labelName"></param>
        /// <returns>string</returns>
        /// <remarks></remarks>
        /// <example></example>
        /// '-----------------------------------------------------------------------------------------
        public static string StringLabelValue(FormView formView, string labelName)
        {
            Label label = FormViewControls.LabelControl(labelName, formView);
            return Values.StringTextValue(label);
        }

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert Label text in a FormView to a datetime value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="labelName"></param>
        /// <returns></returns>
        /// '-----------------------------------------------------------------------------------------
        public static DateTime DateTimeLabelValue(FormView formView, string labelName)
        {
            Label label = FormViewControls.LabelControl(labelName, formView);
            return Values.DateTimeTextValue(label);
        }
    #endregion

        #region Literal Controls
        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert Literal text in a FormView to an int value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="literalName"></param>
        /// <returns></returns>
        /// '-----------------------------------------------------------------------------------------
        public static int IntLiteralValue(FormView formView, string literalName)
        {
            Literal Literal = FormViewControls.LiteralControl(literalName, formView);
            return Values.IntTextValue(Literal);
        }

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert Literal text in a FormView to a decimal value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="literalName"></param>
        /// <returns></returns>
        /// '-----------------------------------------------------------------------------------------
        public static decimal DecimalLiteralValue(FormView formView, string literalName)
        {
            Literal Literal = FormViewControls.LiteralControl(literalName, formView);
            return Values.DecimalTextValue(Literal);
        }

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Get Literal text in a FormView to a string value by using the FCS method Values.StringTextValue
        /// to remove invalid characters and trim the string.
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="literalName"></param>
        /// <returns></returns>
        /// '-----------------------------------------------------------------------------------------
        public static string StringLiteralValue(FormView formView, string literalName)
        {
            Literal Literal = FormViewControls.LiteralControl(literalName, formView);
            return Values.StringTextValue(Literal);
        }

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert Literal text in a FormView to a DateTime value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="literalName"></param>
        /// <returns></returns>
        /// '-----------------------------------------------------------------------------------------
        public static DateTime DateTimeLiteralValue(FormView formView, string literalName)
        {
            Literal Literal = FormViewControls.LiteralControl(literalName, formView);
            return Values.DatetimeTextValue(Literal);
        }
   #endregion

        #region DropDownList Controls
        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Convert DropDownList selected value in a FormView to an integer value
        /// </summary>
        /// <param name="formView"></param>
        /// <param name="dropDownListName"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <example>integer</example>
        /// '-----------------------------------------------------------------------------------------
        public static int IntDropDownListValue(FormView formView, string dropDownListName)
        {
            DropDownList dropDownList = FormViewControls.DropDownListControl(dropDownListName, formView);
            return dropDownList.SelectedItem != null ? Convert.ToInt32(dropDownList.SelectedItem.Value) : int.MinValue;
        }
    #endregion
    }
}
